package com.ctbu.web;

import com.ctbu.tools.VerifyCode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/verify")
public class VerifyCodeController {

    @RequestMapping
    public void verify(HttpServletResponse response, HttpServletRequest request) throws IOException {
        //绘制图形
        VerifyCode vc=new VerifyCode();
        vc.drawImage(response.getOutputStream());

        //获取图像中的验证码
        String code=vc.getCode();
        System.out.println("code"+code);
        //存储--建议redis--当前项目全局对用于
        ServletContext context=request.getServletContext();
        context.setAttribute("backCode",code);

    }

}


